package servlet_stanza_test;

import static org.junit.Assert.*;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;

public class GestioneStanzaTest2 {

	@Before
	public void setUp() throws Exception {
		this.gestione=new gestioneStanza();
	}

	@After
	public void tearDown() throws Exception {
	}

	//Test con una stanza presente nel database
	@Test
	public final void testDoGet() throws ServletException, IOException {


		HttpServletRequest request = mock(HttpServletRequest.class);       
        HttpServletResponse response = mock(HttpServletResponse.class); 

        when(request.getParameter("id_stanza")).thenReturn("6");
        gestione.doGet(request, response);
        int id=gestione.getStanza().getIdStanza();
        assertEquals(id,6);
	}
	
	//Test con una stanza non presente nel database
		@Test
		public final void testDoGet2() throws ServletException, IOException {


			HttpServletRequest request = mock(HttpServletRequest.class);       
	        HttpServletResponse response = mock(HttpServletResponse.class); 

	        when(request.getParameter("id_stanza")).thenReturn("200");
	        gestione.doGet(request, response);
	        assertNull(gestione.getStanza());
	        
		}
		
		// test con l'inserimento di lettere invece di numeri nell'id stanza
		
		@Test
		public final void testDoGet3() throws ServletException, IOException {


			HttpServletRequest request = mock(HttpServletRequest.class);       
	        HttpServletResponse response = mock(HttpServletResponse.class); 

	        when(request.getParameter("id_stanza")).thenReturn("gggg");
	        gestione.doGet(request, response);
	        //Mi aspetto una failure
	        assertNotNull(gestione.getStanza());
	        
		}
		
	private gestioneStanza gestione;
}
